package com.cfwx.designpatterns.proxy.dynamicproxy;

/**
 * JDK动态代理测试类
 * @author Administrator
 */
public class TestDynaProxy {
		public static void main(String[] args) {
			//取得代理类实例
			BookFacadeProxy proxy = new BookFacadeProxy();
			
			//绑定委托类
			BookFacade bookProxy1 = (BookFacade) proxy.bind(new BookFacadeImpl());
			bookProxy1.addBook();
			
			//后面绑定的会使之前的bookProxy1失效,为什么呢？
			//两个对象应用指向了同一堆内存
			BookFacade bookProxy2 = (BookFacade) proxy.bind(new BookFacadeImpl2());
			bookProxy1.addBook();//变成BookFacedImpl2的addBook()方法了
			bookProxy2.addBook(3);
		}

	}
